import { Injectable } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';

import { StepTypes } from './steps.model';

@Injectable()
export class LayerFormsService {

  private _forms: any;
  private _step: StepTypes;
  private _steps: StepTypes[] = [
    StepTypes.info,
    StepTypes.configure,
    StepTypes.other,
    StepTypes.result
  ];

  set forms(forms: any) {
    this._forms = forms;
  }

  get forms(): any {
    return this._forms;
  }

  set step(step: StepTypes) {
    this._step = step;
  }

  get step(): StepTypes {
    return this._step;
  }

  constructor(
    private router: Router
  ) { }

  init(step: StepTypes, values: any = {}): void {
    this.step = step;
    this.forms = values;
  }

  addValues(values: object): void {
    if(!this.forms) {
      this.forms = {};
    }
    this.forms = { ...this.forms, ...values };
  }

  nextStep(): StepTypes {
    const currentIndex: number = this._steps.indexOf(this.step) === -1 ? 0 : this._steps.indexOf(this.step);
    const index: number = currentIndex + 1 === this.step.length ? currentIndex : currentIndex + 1;
    this.step = this._steps[index];
    return this.step;
  }

}
